﻿@namespace MudBlazor
@typeparam T
@inherits MudBaseInput<T>

<CascadingValue Name="Standalone" Value="false" IsFixed="true">
    <div class="mud-select">
        <MudInputControl Label="@Label" Variant="@Variant" HelperText="@HelperText" FullWidth="@FullWidth" Margin="@Margin" Class="@Classname" Style="@Style"
                         Error="@Error" ErrorText="@ErrorText" Disabled="@Disabled" @onclick="@ToggleMenu" Required="@Required">
            <InputContent>
                <MudInput @ref="_elementReference" InputType="@(CanRenderValue || (Strict && !IsValueInList) ? InputType.Hidden : InputType.Text)"
                          Class="mud-select-input" Margin="@Margin" 
                          Variant="@Variant" Value="@(Strict && !IsValueInList ? null : Text)" DisableUnderLine="@DisableUnderLine"
                          Disabled="@Disabled" ReadOnly="true" Error="@Error"
                          OnAdornmentClick="@OnAdornmentClick" AdornmentIcon="@_currentIcon" Adornment="@Adornment" AdornmentColor="@AdornmentColor" IconSize="@IconSize" AdornmentText="@AdornmentText"
                          Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
                          @attributes="UserAttributes" 
                          >
                    @if (CanRenderValue)
                    {
                        @GetSelectedValuePresenter()
                    }
                </MudInput>
            </InputContent>
        </MudInputControl>
        <MudPopover Open=@(_isOpen) MaxHeight="@MaxHeight" Direction="@Direction" OffsetX="@OffsetX" OffsetY="@OffsetY" Class="@PopoverClass">
            <CascadingValue Value="@((IMudSelect)this)" IsFixed="true">
                <MudList Clickable="true" Dense="@Dense">
                    @ChildContent
                </MudList>
            </CascadingValue>
        </MudPopover>
    </div>
</CascadingValue>

<MudOverlay Visible="_isOpen" OnClick="@CloseMenu" LockScroll="false" />

